<?php
/**
 * Add a new Task View
 *
 * @author Xavier VILAIN
 * @license see licence.txt
 */
use Shama\Task;
use Fox\Popup;
use Fox\Html\Screen;

$xview = Xview::instance();
$popup = $xview->val('popup',false);
$execute = $xview->val('execute',false);
$callback = $xview->val('callback',false);
$callback .= "CloseWin(\'pTask\')";
$screen = new Screen('sTask','create',null,true,$callback,0);
$block = Xview::instance()->component('task','info');
$screen->add($block);

if($screen->submitted())
{
	$fields = $screen->get();
	if(!$screen->errors())
	{
		try {
			$task = new Task();
			$task->setFields($fields);
			echo Fox\Message::Success(Msg(Fox\Msg::BUNDLE,Fox\Msg::MSG_CREATE,$task->subject));
			exit;
		}
		catch (Fox\Object\Exception\Save $e)
		{
			Fox\Message::Error($e->getMessage());
		}
	}

}

if($popup && !$screen->submitted())
{
	$title = Msg(Hive::BUNDLE,Hive::TASK_ADD);
	$popup = new Popup('pTask',$title,$screen,800);
	echo $popup->display();
}
else
{
	echo $screen->display();
}